package com.oxygen.pt.mapper;


import com.oxygen.pt.pojo.dto.PressureVesselInspectionDailySaveDTO;
import com.oxygen.pt.pojo.entity.PressureVesselInspectionDaily;
import com.oxygen.pt.pojo.vo.OxygenChamberInspectionPageVO;
import com.oxygen.pt.pojo.vo.PressureVesselDailyExportVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface PressureVesselInspectionDailyMapper {

    /** 新增一条记录 */
    int insert(PressureVesselInspectionDailySaveDTO dto);

    /** 根据主键删除 */
    int deleteById(@Param("id") Long id);

    /** 根据主键查询 */
    PressureVesselInspectionDaily selectById(@Param("id") Long id);

    /** 全字段更新 */
    int updateById(@Param("id") Long id,
                   @Param("dto") PressureVesselInspectionDailySaveDTO dto);

    List<OxygenChamberInspectionPageVO> selectOxygenChamberPage(
            @Param("inspector") String inspector,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime")    LocalDateTime endTime);

    @Select("SELECT " +
            "  DATE_FORMAT(inspect_time, '%Y-%m-%d') AS inspectDate, " +  // 字段名与VO属性保持一致
            "  IF(work_pressure = 0, '√', '×') AS workPressure, " +
            "  IF(work_temp = 0, '√', '×') AS workTemp, " +
            "  IF(safety_valve = 0, '√', '×') AS safetyValve, " +
            "  IF(damage_corr = 0, '√', '×') AS damageCorr, " +
            "  IF(insulation = 0, '√', '×') AS insulation, " +
            "  IF(external_label = 0, '√', '×') AS externalLabel, " +
            "  IF(leak_conn = 0, '√', '×') AS leakConn, " +
            "  IF(support_abnormal = 0, '√', '×') AS supportAbnormal, " +
            "  IF(valve_status = 0, '√', '×') AS valveStatus, " +
            "  remark_other_abnormal AS otherAbnormalDetail " +
            "FROM pressure_vessel_inspection_daily " +
            "WHERE inspect_time BETWEEN #{start} AND #{end} " +
            "ORDER BY inspect_time ASC")
    List<PressureVesselDailyExportVO> listForExport(
            @Param("start") LocalDateTime start,
            @Param("end") LocalDateTime end);
}